
#ifndef __ECDSA_PUBLIC_KEY_H
#define __ECDSA_PUBLIC_KEY_H

#include <openssl/ecdsa.h>
#include "../iface/SSLInterface.h"
#include "PublicKey.h"
#include "CheckingKey.h"

/** An class encapsulating an ECDSA public key. */
class ECDSAPublicKey : public PublicKey, public CheckingKey
{
   public:
      ECDSAPublicKey();
      ECDSAPublicKey(const char *name);
      // Construct a duplicate of the public key
      ECDSAPublicKey(const ECDSAPublicKey &other);
      // Construct from PEM format
      ECDSAPublicKey(const char *pemtext, const char *name);
      // Construct from OpenSSL format
      ECDSAPublicKey(EC_KEY *pubkey, const char *name);
      // Copy assignment operator
      ECDSAPublicKey &operator=(const ECDSAPublicKey &other);
      // Destroy public key
      ~ECDSAPublicKey();
      // Get new OpenSSL ECDSA object
      int getSSLKeyComponents(EC_KEY **pubkey) const;
      // Get PEM data
      int getPEMKeyData(char **pemtext, const char *password) const;
      // Get OpenSSH binary blob
      int getSSHKeyBlob(char **blob, int *reallength) const;
      // Get OpenSSH text with key label
      int getSSHKeyBlob(char **textblob, const char *keylabel) const;
      // Compare key to key
      int compareKeyEqual(PublicKey *pubkey) const;
      // Get key type name
      static const keytypetype getStaticKeyType() { return KEY_TYPE_PUBLIC_ECDSA; }
      const keytypetype getKeyType() const { return KEY_TYPE_PUBLIC_ECDSA; }
      // General import key function that others call.
      int importPublicKeyWithOptionalPassword(const char *pemtext, const char *password);
      // To import from text - Base64 RAW or PEM
      int importKeyFromASCII(const char *text, const char *name);
      // To export to text - Base64 RAW or PEM
      int exportKeyToASCII(char **text) const;
      // Import from text with password
      int importKeyFromASCIIWithPassword(const char *text, const char *password, const char *name);
      // Export to text with password
      int exportKeyToASCIIWithPassword(char **text, const char *password) const;
   private:
      static int copyECDSASSLPublicKey(EC_KEY *dst, EC_KEY *src);
      /** A pointer to the real ECDSA public key, held in SSL
       * format. */
      EC_KEY *key;
      /** A pointer to the curve group type. */
      EC_GROUP *group;
};

#endif
